package com.huawei123.hasee.cniao5store.api;

import com.huawei123.hasee.cniao5store.bean.CategoryBean;
import com.huawei123.hasee.cniao5store.utils.JsonParseUtils;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import com.zhxu.library.api.BaseApi;
import com.zhxu.library.listener.HttpOnNextListener;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Retrofit;
import rx.Observable;

/**
 * 项目名称：Cniao5Store
 * 类描述：
 * 创建人：luohao
 * 创建时间：2018/1/30 1:06
 * 修改人：luohao
 * 修改时间：2018/1/30 1:06
 * 修改备注：
 */

public class CategoryApi extends BaseApi<CategoryBean>{

    public CategoryApi(HttpOnNextListener listener, RxAppCompatActivity rxAppCompatActivity) {
        super(listener, rxAppCompatActivity);
        setMothed("AppStore/category");
    }

    @Override
    public Observable getObservable(Retrofit retrofit) {
        HttpGetService httpGetService = retrofit.create(HttpGetService.class);
        return httpGetService.getCategoryData();
    }

    @Override
    public CategoryBean call(ResponseBody responseBody) {
        String json="";
        try {
            json=responseBody.string();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return JsonParseUtils.parseCategoryBean(json);
    }
}
